package com.api.workflow.web;

import com.alibaba.fastjson.JSONObject;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wanghan
 * @version 1.0
 * @Description 应付账款解冻
 * @since 2025/2/27 12:29
 */
public class ThawFrozenAction extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
        try {
            BaseBean baseBean = new BaseBean();
            String requestid = requestInfo.getRequestid();
            String workflowid = requestInfo.getWorkflowid();

            int formid = requestInfo.getRequestManager().getFormid();
            int formidAbs = Math.abs(formid);// 流程表单id绝对值
            String tableDBName = "formtable_main_" + formidAbs;

            // 主表数据
            MainTableInfo mainTableInfo = requestInfo.getMainTableInfo();
            Property[] property = mainTableInfo.getProperty();
            //这里是存储了主表全部的数据  可自行修改存储结构
            Map<String, Object> mainTableInfoMap = new HashMap<>();
            for (int i = 0; i < property.length; i++) {
                String name = property[i].getName().toLowerCase();
                mainTableInfoMap.put(name, Util.null2String(property[i].getValue()));
            }
            baseBean.writeLog("==========ThawFrozenAction===mainTableInfoMap:" + JSONObject.toJSONString(mainTableInfoMap));
            String wybs = "" + mainTableInfoMap.get("BUKRS") + mainTableInfoMap.get("GJAHR") + mainTableInfoMap.get("BELNR") + mainTableInfoMap.get("BUZEI");
            baseBean.writeLog("=============ThawFrozenAction:" + wybs);
            RecordSet recordSet = new RecordSet();
            String sql = "update uf_yfzkbd set ycbs=0 where wybs=?";
            baseBean.writeLog("==========ThawFrozenAction===sql:" + sql);
            recordSet.executeUpdate(sql, wybs);
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessagecontent("接口出错,请联系管理员!" + e.getMessage());
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
